package cm.epet.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import cm.epet.ConnectionHelper;
import cm.epet.dao.Interface.IAccountDAO;

public class AccountDAO implements IAccountDAO{
	static int i=0;
	public static void createAccount(int deal_type,String pet_name,String seller_name,String buyer_name,double price,java.util.Date deal_time) throws SQLException
	{
		Connection con = null;
		// TODO Auto-generated method stub
		try {
			con = ConnectionHelper.getConnection();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Statement stmt = con.createStatement();
		ResultSet rs = null;
		rs = stmt.executeQuery("select id from account");
		if(rs.next()) {
			rs.afterLast();
			rs.previous();
			i=rs.getInt(1)+1;
		}
		else {
			i=1;
		}
		stmt.executeUpdate("insert into account(id,deal_type,pet_name,seller_name,buyer_name,price,deal_time) values("
				+ "'"+i+"','"+deal_type+"','"+pet_name+"','"+seller_name+"','"+buyer_name+"','"+price+"','"+deal_time+"')");
	}
}
